#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do
  case "$OPT" in
    ?)
      common_getopts_case "$OPT"
      ;;
  esac
done
common_setup
kernel_dir="${common_build_dir}/linux-custom"
(
  if "$common_gem5"; then
    sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file"
  else
    sed -r 's/.*pc=//' "$common_trace_txt_file"
  fi
) | \
  xargs "${common_host_dir}/bin/${common_arch}-linux-addr2line" -e "${common_vmlinux}" -fp | \
  sed -E "s|at ${kernel_dir}/(\./\|)||" | \
  uniq -c \
> "${common_run_dir}/trace-lines.txt"
